package com.moolng.service.impl;

import com.moolng.service.AccountApi;
import io.seata.rm.tcc.api.BusinessActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.math.BigDecimal;

/**
 * @author 李权
 * @description
 * @date 2021/1/6 18:09
 */
@Service
public class AccountApiImpl implements AccountApi {
    
    @Autowired
    private RestTemplate restTemplate;
    
    
    @Override
    public boolean prepare(BusinessActionContext actionContext, Long userId, BigDecimal money) {
        return restTemplate.getForObject("http://service01/s2/prepare", Boolean.class);
    }
    
    @Override
    public boolean commit(BusinessActionContext actionContext) {
        return restTemplate.getForObject("http://service01/s2/commit", Boolean.class);
    }
    
    @Override
    public boolean rollback(BusinessActionContext actionContext) {
        return restTemplate.getForObject("http://service01/s2/rollback", Boolean.class);
    }
}
